<template>
  <div>
    <template v-for="el in messageInfo">
      <div v-bind:key="el._id" class="card col-md-6 col-sm-12 overflow-hidden" style="position: relative;">
        <div class="card-body">
          <p class="card-title"><span>{{ el.user[0].name }}申请加入{{ el.team[0].name }}</span></p>
          <h6 class="card-subtitle mb-2 text-muted">申请时间：{{ el.updateTime|time }}</h6>
          <div>
            <p>
              申请信息<a data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false"
                     aria-controls="collapseExample">
              点击查看
            </a>
            </p>
            <div class="collapse" id="collapseExample">
              <div class="card card-body">
                <p class="card-text">姓名：{{ el.user[0].name }}</p>
                <p class="card-text">性别：{{ el.user[0].sex|sex }}</p>
                <p class="card-text">身份证号：{{ el.user[0].IDCard }}</p>
                <p class="card-text">学校：{{ el.user[0].schoolName }}</p>
                <p class="card-text">学号：{{ el.user[0].Sno }}</p>
                <p class="card-text">学院：{{ el.user[0].collegeName }}</p>
                <p class="card-text">专业：{{ el.user[0].majorName }}</p>
                <p class="card-text">联系电话：{{ el.user[0].tel }}</p>
              </div>
            </div>
          </div>
          <div class="text-center">
            <button type="button" class="btn btn-primary" @click="handleEnter(el)">同意</button>
          </div>
        </div>
      </div>
    </template>
    <template v-if="messageInfo.length===0">
      <el-empty class="border" description="暂无消息通知"></el-empty>
    </template>
  </div>
</template>

<script>
import user from "../../../api/user";
import time from "../../../filter/time";
import sex from "../../../filter/sex";

export default {
  name: "myMessage",
  data() {
    return {
      messageInfo: []
    }
  },
  mounted() {
    this.GetAllMessage()
  },
  filters: {
    time,
    sex
  },
  methods: {
    // 同意加入
    handleEnter(el) {
      let children = el.team[0].children
      children.push({
        userID: el.user[0]._id,
        userName: el.user[0].name
      })
      const param = {
        teamID: el.teamID,
        children,
        midID: el._id
      }
      user.ConfirmJoinTeam(param).then(() => {
        this.GetAllMessage()
      })
    },

    // 获取消息
    GetAllMessage() {
      user.GetAllMessage().then(r => {
        let data = r.data.data.mid
        this.messageInfo = data.filter(v => v.userID === this.$store.getters["userStore/userInfo"]._id)
      })
    }
  }
}
</script>

<style scoped>

</style>